﻿using Application.AppService.Config;
using Application.AppService.IConfig.Dto.Config_file_third_kind;
using AutoMapper;
using Domain.Entity.Config;
using Domain.Repository.IConfig;
using Microsoft.AspNetCore.Mvc;

namespace UI.Controllers
{
    public class CFTKController : Controller
    {
        private readonly IConfig_file_third_kindAppService cFTKAppService;
        private readonly IMapper mapper;

        public CFTKController(IConfig_file_third_kindAppService CFTKAppService, IMapper mapper)
        {
            cFTKAppService = CFTKAppService;
            this.mapper = mapper;
        }
        public IActionResult Index()
        {
            return View();
        }

        public async Task<IActionResult> AddCFTK(Config_file_third_kind cFTK)
        {
            int i = await cFTKAppService.AddCFTKAsync(cFTK);
            return Json(i);
        }

        [HttpPost("GetCFTK")]
        public async Task<IActionResult> GetCFTK()
        {
            List<Config_file_third_kind> cFTKs = await cFTKAppService.GetCFTKAsync();
            return Json(cFTKs);
        }

        public async Task<IActionResult> UpdateCFTK(Config_file_third_kindUpdateDto cFTKUpdate)
        {
            Config_file_third_kind aFTK = mapper.Map<Config_file_third_kind>(cFTKUpdate);
            int i = await cFTKAppService.UpdateCFTKAsync(aFTK);
            return Json(i);
        }

        public async Task<IActionResult> DeleteCFTK(int id)
        {
            int i = await cFTKAppService.DeleteCFTKAsync(id);
            return Json(i);
        }

        [HttpPost("GetCFTKById")]
        public async Task<IActionResult> GetCFTKById(string id)
        {
            List<Config_file_third_kind> cFTKs = await cFTKAppService.GetCFTKAsyncById(id);
            return Json(cFTKs);
        }

    }
}
